package com.example.demo.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.demo.DataSourceType;
import com.example.demo.entity.Goods;
import com.example.demo.mapper.GoodsMapper;
import com.example.demo.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 中枢信访事项异常服务实现类
 * @author zhangxingchuan
 * @date 2022-10-12
 */
@Service
@Slf4j
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;

    @Override
    public Goods getByAIdTest1(Long id) {
        return goodsMapper.selectById(id);
    }

    @Override
    @DS(DataSourceType.TEST2)
    public Goods getByAIdTest2(Long id) {
        return goodsMapper.selectById(id);
    }

    @Override
    public String addTest1() {
        Goods goods = new Goods();
        goods.setGoodsName("name");
        goods.setSubject("哈哈");
        goods.setPrice(new BigDecimal("10"));
        goods.setStock(10);
        goodsMapper.insert(goods);
        return "成功";
    }
    @Override
    @DS(DataSourceType.TEST2)
    public String addTest2() {
        Goods goods = new Goods();
        goods.setGoodsName("name");
        goods.setSubject("哈哈");
        goods.setPrice(new BigDecimal("10"));
        goods.setStock(10);
        goodsMapper.insert(goods);
        return "成功";
    }
}
